'''
Created on Feb 10, 2011 Sample Text

This script will generate Mark Griffis.  Simply call:

$ python gen_skeleton

and Mark Griffis will appear.

@author: mikeg
'''

import io
import os
import re
from optparse import OptionParser

# Seriously though, this script will generate a barebones hydra_config.ini.
# Using command line flags, one can change what the skeleton will look like.
# 
# Ex: $ python gen_skeleton.py -s 13:10:8:5:1:1 -o hydra_config.ini
# Where -s is the setup of the test:
#
# Consider the -s arg 'A:B:C:D:E:F'
#
# A -> Number of TCNs
# B -> Number of POPs
# C -> Number of SNEs
# D -> Number of RHNs
# E -> Number of STTs
# F -> Number of NOSCs
#
# Using the example given, this will generate SNMP and NMS config sections for
# 13 TCNs, 10 POPs, 8 SNEs, 5 RHNs, 1 STT, and 1 NOSC

def parse_cmd_line():
    """Gather command line args and handle them accordingly."""
    parse_opts = OptionParser()
    parse_opts.add_option("-c", "--comp", dest="comp", action="store",
                          metavar="SETUP", help="Use -s to specify the composition \
                          of the test your are building the config for. The string \
                          should be formatted like so: \
                          -s #TCNs:#POPs:#SNEs:#RHNs:#STTs:#NOSCs \ ex: -s 5:3:4:1:3:1")

    parse_opts.add_option("-o", "--outfile", dest="outfile", action="store",
                          metavar="OUTFILE", help="Use -o to specify an output file \
                          to store the config skeleton in.")

    (options, args) = parse_opts.parse_args()

    if options.comp is None:
        print "No composition was given.  Please specify a comp using the -c flag. Use the -h flag for help."
        return None
    
    if options.outfile is None:
        print "No outfile was supplied.  Please specify an output file using the -o flag. Use the -h flag for help."
        return None
    
        print "Using input parameters:"
        print "Composition = ", options.comp
        print "Output file = ", options.outfile
    
    return options

def parse_comp(compstring):
    """Split the composition command line arg into usable CI counts."""
    segments = compstring.split(":")
    num_tcn = segments[0]
    num_pop = segments[1]
    num_sne = segments[2]
    num_rhn = segments[3]
    num_stt = segments[4]
    num_nosc = segments[5]
    return num_tcn, num_pop, num_sne, num_rhn, num_stt, num_nosc

class TcnWan:
    """TCN WAN class"""
    
#class snmpskele:
#    """Skeleton class for SNMP config section"""
#    
##    NUM_HNR_QUERIES = 3
##    NUM_MPM_QUERIES = 3
##    NUM_WANRTR_QUERIES = 1
##    NUM_MARRTR_QUERIES = 2
##    NUM_WANSWITCH_QUERIES = 1
##    NUM_LANQED_QUERIES = 2
##    NUM_LANSWITCH_QUERIES = 1
##    NUM_LANRTR_QUERIES = 1
#    oid_chunk = "wtf is dis"
#    
#    query_chunk = "\
#[[[[interval]]]]\n\
#    interval=\n\
#    [[[[[query]]]]]\n\
#        label=\n\
#        size=\n\
#        %s\n\
#    [[[[[end]]]]]\n\
#[[[[end]]]]" % (oid_chunk,)
#    
#    snmp_chunk =  "\
#        [[[session]]]\n\
#            ip=\n\
#            user=\n\
#            port=\n\
#            timeout=\n\
#            retries=\n\
#            version=\n\
#            securityLevel=\n\
#            authProto=\n\
#            authPass=\n\
#            privacy=\n\
#            privPass=\n\
#            [[[[interval]]]]\n\
#                interval=\n\
#                [[[[[query]]]]]\n\
#                    label=\n\
#                    size=\n\
#                    %s\n\
#                [[[[[end]]]]]\n\
#            [[[[end]]]]\n\
#        [[[end]]]" % (query_chunk,)   
#    
#    def __init__(self, outfile):
#        self.outfile = outfile
#        
#    def gen_tcn_skele(self, outfile):
#        f_skeleton = open(outfile, "wb")
#        f_skeleton.write(snmp_chunk)


if __name__ == '__main__':
    options = parse_cmd_line()
    if options is None:
        exit()
   
    n_tcn, n_pop, n_sne, n_rhn, n_stt, n_nosc = parse_comp(options.comp)
    print n_tcn
    
   # snmpskele.gen_tcn_skele(options.outfile)
    
